<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 列表控制器
 */
class Category extends CI_Controller {

    public function __construct () {
        parent::__construct();
        $this->load->model('Article_model', 'article');
        $this->load->model('Category_model', 'cate');
    }

    /**
     * 列表视图
     */
    public function index () {
        $perPage = 5;
        $this->load->helper('page');
        $cid = $this->uri->segment(4);
        $page = $this->uri->segment(5);
        $page = $page ? intval($page) : 1;
        $offset = !empty($page) ? ($page - 1)*$perPage : $perPage;
        $this->db->limit($perPage, $offset);
        $data['article']  = $this->article->getArticleList($cid);
        $data['category'] = $this->cate->getAll();
        $data['link'] = indexPageCreate('index/category/index/'.$cid,$this->article->categoryArticleCount($cid),$perPage);
        $this->load->view('index/category.php', $data);
    }
}